package com.example.springbootdemo.controller;

import com.xhs.common.error.XhsErrorException;
import com.xhs.miniapp.api.XhsMaService;
import com.xhs.miniapp.bean.XhsMaJscode2SessionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author ws
 * @create 2025/7/24 11:09
 */
@RestController
@RequestMapping("/xhs")
public class XhsController {

    @Autowired
    private XhsMaService xhsMaService;

    @GetMapping("/notify")
    public String test(String nonce, String timestamp, String echostr, String signature) throws XhsErrorException {
        System.out.println(xhsMaService.getAccessToken());
        boolean b = xhsMaService.checkSignature(timestamp, nonce, signature);
        System.out.println(xhsMaService.getAccessToken());
        if(b){
            return echostr;
        }
        return "来源不是小红书";
    }

    @GetMapping("/testLogin")
    public String gg(String code) throws XhsErrorException {
        XhsMaJscode2SessionResult sessionInfo = xhsMaService.getUserService().getSessionInfo(code);
        System.out.println(sessionInfo);
        return sessionInfo.getOpenid();
    }

}
